
const { db, command, cloud } = require(':share/webServer')
const useMidware = require(':utils/useMidware')
const checkJson = require(':utils/checkJson')
const { dbCheck } = require(':utils/cloudCheck')

async function checkData(ctx, next)
{
    const scheam = {
        type: 'object',
        properties: {
            roulette_id: { type: 'number' }
        },
        required: ['roulette_id']
    }
    checkJson(ctx.request.body, scheam)
    await next()
}

async function deleteRoulette(ctx, next)
{
    const { roulette_id } = ctx.request.body
    console.log(roulette_id)
    let rsp = dbCheck(await db.collection('Roulettes').where({
        roulette_id
    }).remove(), { noEmpty: true })

    await db.collection('Roulettes_info').where({
        name: 'roulette_num'
    }).update({
        value: command.inc(-1)
    })
    await next()
}

useMidware.post('/modules/adminPage/manageRoulette/deleteRoulette', checkData)
useMidware.post('/modules/adminPage/manageRoulette/deleteRoulette', deleteRoulette)